﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Reflection;
using DevExpress.XtraEditors;

namespace Sheeter.App
{
    public partial class UscNivel : UserControl
    {
        public UscNivel()
        {
            InitializeComponent();
            RemoveEventos(); //remover para ativar eventos
        }

        private void AdicionaEventos()
        {
            nvl1.CheckedChanged += nvl1_CheckedChanged;
            nvl2.CheckedChanged += nvl2_CheckedChanged;
            nvl3.CheckedChanged += nvl3_CheckedChanged;
            nvl4.CheckedChanged += nvl4_CheckedChanged;
            nvl5.CheckedChanged += nvl5_CheckedChanged;
        }

        private void RemoveEventos()
        {
            nvl1.CheckedChanged -= nvl1_CheckedChanged;
            nvl2.CheckedChanged -= nvl2_CheckedChanged;
            nvl3.CheckedChanged -= nvl3_CheckedChanged;
            nvl4.CheckedChanged -= nvl4_CheckedChanged;
            nvl5.CheckedChanged -= nvl5_CheckedChanged;
        }

        private void nvl1_CheckedChanged(object sender, EventArgs e)
        {
            RemoveEventos();
            //
            for (int i = (Controls.Count - 1); i > 0; i--)
            {
                if ((Controls[i] as CheckEdit).Checked.Equals(false))
                    (Controls[i] as CheckEdit).Checked = true;
                else
                    (Controls[i] as CheckEdit).Checked = false;

                if ((Controls[i] as CheckEdit).Name.Equals("nvl1"))
                    break;
            }
            //
            AdicionaEventos();
        }

        private void nvl2_CheckedChanged(object sender, EventArgs e)
        {
            RemoveEventos();
            //
            for (int i = (Controls.Count - 1); i > 0; i--)
            {
                if ((Controls[i] as CheckEdit).Checked.Equals(false))
                    (Controls[i] as CheckEdit).Checked = true;
                else
                    (Controls[i] as CheckEdit).Checked = false;

                if ((Controls[i] as CheckEdit).Name.Equals("nvl2"))
                    break;
            }
            //
            AdicionaEventos();
        }

        private void nvl3_CheckedChanged(object sender, EventArgs e)
        {
            RemoveEventos();
            //
            for (int i = (Controls.Count - 1); i > 0; i--)
            {
                if ((Controls[i] as CheckEdit).Checked.Equals(false))
                    (Controls[i] as CheckEdit).Checked = true;
                else
                    (Controls[i] as CheckEdit).Checked = false;

                if ((Controls[i] as CheckEdit).Name.Equals("nvl3"))
                    break;
            }
            //
            AdicionaEventos();
        }

        private void nvl4_CheckedChanged(object sender, EventArgs e)
        {
            RemoveEventos();
            //
            for (int i = (Controls.Count - 1); i > 0; i--)
            {
                if ((Controls[i] as CheckEdit).Checked.Equals(false))
                    (Controls[i] as CheckEdit).Checked = true;
                else
                    (Controls[i] as CheckEdit).Checked = false;

                if ((Controls[i] as CheckEdit).Name.Equals("nvl4"))
                    break;
            }
            //
            AdicionaEventos();
        }

        private void nvl5_CheckedChanged(object sender, EventArgs e)
        {
            RemoveEventos();
            //
            for (int i = Controls.Count; i > 0; i--)
            {
                if ((Controls[i] as CheckEdit).Checked.Equals(false))
                    (Controls[i] as CheckEdit).Checked = true;
                else
                    (Controls[i] as CheckEdit).Checked = false;

                if ((Controls[i] as CheckEdit).Name.Equals("nvl5"))
                    break;
            }
            //
            AdicionaEventos();
        }
    }
}
